﻿using System.Collections.Generic;
using System.Diagnostics;
using System.ServiceProcess;

namespace VoteEventService
{
    public partial class Service1 : ServiceBase
    {
        System.Timers.Timer timer = new System.Timers.Timer();
        private const string LOG_PATH = "D://ServiceLog/Logging/";

        public Service1()
        {
            InitializeComponent();
            this.ServiceName = "EventVoteService";
        }

        protected override void OnStart(string[] args)
        {
            DebugMode();
            timer = new System.Timers.Timer();
            timer.Interval = Helper.TimerInterval();
            timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
            timer.Start();
        }

        void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            List<VoteLogObject> datas = Helper.GetFromMessageQueues(Helper.TotalItemsEachBatch());
            Helper.UpdateToSQL(datas);
        }

        protected override void OnStop()
        {
        }

        [Conditional("DEBUG_SERVICE")]
        private static void DebugMode()
        {
            Debugger.Break();
        }
    }
}
